home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / SPIM Folder / Sources / MAC-PORT-NOTES < prev    next >
Encoding:
Text File  |  1993-02-10  |  4.8 KB  |  114 lines  |  [TEXT/KAHL]

  1. NOTES ON THE PORT OF SPIM TO THE MACINTOSH
  2. ==========================================
  3.  
  4. Getting it to compile:
  5. ----------------------
  6.  
  7. I am starting from the NT Windows port by Scott Rose.
  8.  
  9. I use the preprocessor symbol MACINTOSH to distinguish Mac OS-specific constructs from
  10. their Unix or NT equivalents. THINK C provides a way to automatically define this symbol
  11. in every source file. Users of other compilers might have to insert it by hand.
  12.  
  13. I eventually realized I had to #define BIGENDIAN in this same automatic manner.
  14.  
  15. In spim.h, I don't include <sys/types.h>.
  16.  
  17. In lex_yy.c, I cast the first argument of calls to sscanf() as (char *). This is
  18. really a change to scanner.l, but I don't have lex.
  19.  
  20. In run.c, I don't include the X11 stuff, but I do include spim-sys.h and lex_yy.h.
  21.  
  22. In mem.h, I cast the last argument of calls to bad_mem_read() as (mem_word *).
  23.  
  24. In spim-uti.c, I make the Mac version import the same things as the NT version, and
  25. define DEFAULT_TRAP_HANDLER to "trap.handler". I still have to figure out where to
  26. search for the default handler on the Mac.
  27.  
  28. In sym_tab.c, the hash table is too big. Instead of a large prime around 8000, I
  29. will use one around 4000, namely 4001. It might be better to malloc the table at
  30. run time.
  31.  
  32. In y_tab.c, I made the argument to yyerror "const" char *. I also changed many
  33. examples of "yypvt[x] = NULL" to "yypvt[x] = 0". I added a declaration of store_byte().
  34. I added typedef void (*VoidProc)(), made this the type of store_op, and cast
  35. store_half() to this type. I changed two more NULLs to 0; do diff against Scott's
  36. code to find them. I cast the argument to free() as void *.
  37.  
  38. Once again, I touched y_tab.c because I don't have yacc. The real source file is
  39. parser.y.
  40.  
  41. In inst.c, I cast the last argument to qsort() as CompareFunc, which is my own typedef.
  42.  
  43. I rewrote the memory access macros in mem.h as functions. I rewrote the
  44. register access macros in reg.h as functions. Code for all of them lives in mem.c.
  45. Let's get on with it!
  46.  
  47. With THINK C on a Macintosh II, there is a lengthy delay (more than a minute) after
  48. compiling run_spim(). The machine is not hung, just doing something non-linear.
  49.  
  50. Getting it to link:
  51. -------------------
  52.  
  53. I get many "multiply defined" errors because of the promiscuous use of external variables.
  54. I use a trick where the .c file that defines the variables in a .h file must first
  55. define a symbol. Other .c files including the same .h leave the symbol undefined and
  56. so get external declarations.
  57.  
  58. I did the above to mem.h and reg.h.
  59.  
  60. In spim.h, I simply made console_out and message out external.
  61.  
  62. In sym_tbl.c, I declared data_dir external.
  63.  
  64. I had to define bcmp(), bcopy() and bzero(), just as Scott did.
  65.  
  66. In spim-uti.c, I removed the reference to environ. The Mac has no concept of environ,
  67. argc, or argv. I declared input_file_name external.
  68.  
  69. Building an interface:
  70. ----------------------
  71.  
  72. THINK C automatically includes several commonly-used header files for Toolbox and OS
  73. functions, such as QuickDraw, WindowMgr, and the like. Other Mac compilers may require
  74. these to be explicitely given.
  75.  
  76. I had to tell THINK C to use "far data", 4-byte ints and 8-byte doubles. I recompiled
  77. versions of the ANSI and Unix libraries so they had the same characteristics.
  78.  
  79. The menu and dialog design is based on Scott's NT port. I'm not trying to be any
  80. fancier than he is.
  81.  
  82. I ifdeffed out the copyright notice output in spim-uti.c. The Mac has a better way
  83. to present this information. I also put in a call to MacFatalError(), which is defined
  84. in macspim.c.
  85.  
  86. I touched lex_yy.c to make it call fatal_error() (in spim_uti.c) instead of exit().
  87. This should be in everybody's code.
  88.  
  89. I wrote my own malloc() and free() routines that try to be smarter about Mac memory
  90. limitations. I am also finding lots of places where malloc() is called but the
  91. result is not tested for validity. I fixed this in inst.c and lex_yy.c. I removed
  92. mem.c from the SPIM flavor of the ANSI library.
  93.  
  94. I found some more unchecked malloc() calls in sym_tbl.c. The person who decided to
  95. make malloc() the first argument to strcpy should be shot!
  96.  
  97. In inst.c, I added a routine to set break_inst back to NULL to force a new malloc.
  98. I need this after clearing all. Any other static malloc'ed pointers I discover will
  99. also need to get renullified in this case. A headache, but at least memory isn't
  100. crashing me anymore.
  101.  
  102. Testing:
  103. --------
  104. It won't run tt.alu.bare.s because that file is for little-endian machines.
  105.  
  106. The .half directive was broken. Store_half() must have its parameter declared as int,
  107. not short, because the parser will always pass four bytes to any of the store_x()
  108. routines. On a big-endian machine, this breaks. (Store_half() is in data.c).
  109.  
  110. It ran tt.fpu.bar.s and tt.SAL.s without any problems.
  111.  
  112. In spim_uti.c, I added program_starting_address = 0 to initialize_world(). This is
  113. probably a bug in everybody's version.
  114.